package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author alexis
 * @date 2025-03-05
 */
@Api(tags = "预约信息管理")
@RestController
@RequestMapping("/member/reservation")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 查询预约信息列表
     */
    @ApiOperation("查询预约信息列表")
    @GetMapping("/page")
    public R<TableDataInfo<Reservation>> list(@ApiParam("预约信息查询条件") Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list));
    }


    /**
     * 新增预约信息
     */
    @ApiOperation("新增预约信息")
    @PostMapping
    public AjaxResult add(@ApiParam("预约信息信息") @RequestBody Reservation reservation)
    {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 查询当天取消预约数量
     */
    @ApiOperation("查询当天取消预约数量")
    @GetMapping("/cancelled-count")
    public R<Long> cancelledCount(){
        return R.ok(reservationService.cancelledCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     */
    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public R<List<TimeVo>> countByTime(Long time){
        return R.ok(reservationService.countByTime(time));
    }

    /**
     * 取消预约
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return success();
    }
}
